import requests


class SendMethod:
    @staticmethod
    # 请求
    def send_method(method, url, params=None, data=None, json=None):
        if method == 'get':
            response = requests.get(url=url, params=params)
        elif method == 'post':
            response = requests.post(url=url, data=data, json=json)
        else:
            response = None
            print('不支持该请求方式')

        # 响应
        result = {}
        if response is not None:
            result['status_code'] = response.status_code
            result['headers'] = response.headers
            result['body'] = response.json()
            result['response_time'] = int(response.elapsed.microseconds / 1000)
            return result
        else:
            return response


if __name__ == '__main__':
    url = 'http://127.0.0.1:8000/api/add_event/'
    data = {
        'eid': '556',
        'name': '苹果14s',
        'limit': '20',
        'status': '1',
        'address': '源码时代',
        'start_time': '2022-7-20'
    }
    print(SendMethod.send_method('post', url=url, data=data))
